package com.pangu.impl;

import com.squareup.okhttp.RequestBody;

import java.security.KeyStore;
import java.util.Map;

/**
 * 协议的封装
 * <p/>
 * Created by cuijianhui_91
 */
public class ProtocolWrap {

    // 处理好的参数数据： ac=xx&qid=xx
    private String getData;
    // Post数据
    private RequestBody postBody;
    // header 数据部分
    private Map<String, String> headerValues;
    // 连接主机，如同这个值没有设置将使用默认的主机
    private String host;
    // 连接超时
    private int connectTimeout = -1;
    // 读取超时(负数的时候不起作用)
    private int soTimeout = -1;
    // 是否启动连接重试机制，默认是重试的。
    private boolean reTry = true;
    // 是否是https请求
    private boolean isHttps = false;
    // https链接独有的https证书
    private KeyStore httpsKeyStore;

    public String getGetData() {
        return getData;
    }

    public void setGetData(String getData) {
        this.getData = getData;
    }

    public void setPostBody(RequestBody body) {
        this.postBody = body;
    }

    public RequestBody getPostBody() {
        return postBody;
    }

    public Map<String, String> getHeaderValues() {
        return headerValues;
    }

    public void setHeaderValues(Map<String, String> headerValues) {
        this.headerValues = headerValues;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getConnectTimeout() {
        return connectTimeout;
    }

    public void setConnectTimeout(int connectTimeout) {
        this.connectTimeout = connectTimeout;
    }

    public int getSoTimeout() {
        return soTimeout;
    }

    public void setSoTimeout(int soTimeout) {
        this.soTimeout = soTimeout;
    }

    public boolean isReTry() {
        return reTry;
    }

    public void setReTry(boolean reTry) {
        this.reTry = reTry;
    }

    public boolean isHttps() {
        if (host != null && host.indexOf("http") == 0) {
            return host.indexOf("https") == 0;

        } else {
            return isHttps;
        }
    }

    public void setIsHttps(boolean isHttps) {
        this.isHttps = isHttps;
    }

    public KeyStore getHttpsKeyStore() {
        return httpsKeyStore;
    }

    public void setHttpsKeyStore(KeyStore httpsKeyStore) {
        this.httpsKeyStore = httpsKeyStore;
    }

    @Override
    public String toString() {
        return "ProtocolWrap{" +
                "getData='" + getData + '\'' +
                ", postBody=" + postBody +
                ", headerValues=" + headerValues +
                ", host='" + host + '\'' +
                ", connectTimeout=" + connectTimeout +
                ", soTimeout=" + soTimeout +
                ", reTry=" + reTry +
                ", isHttps=" + isHttps +
                ", httpsKeyStore=" + httpsKeyStore +
                '}';
    }
}
